<?php
/**
 * @link https://www.kancloud.cn/cleverstone/ymb2
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

namespace builder\form\util\control\xselect;

use builder\helper\Url;

/**
 * xselect远程搜索(自定义搜索)
 * @desc 该控件用于补充select2相关控件的不足
 * @author cleverstone
 * @since ym2.0
 * @see https://maplemei.gitee.io/xm-select/#/plugin/cascader
 */
class XselectRemote extends Xselect
{
    protected function init()
    {
        $this->options['control'] = 'xselect_remote';
        $this->options['pluginOptions']['remoteSearch'] = true;
        $this->options['method'] = 'get';
        $this->options['url'] = '';
    }

    /**
     * 开启远程分页
     * @return $this
     */
    public function pageRemote()
    {
        $this->options['pluginOptions']['pageRemote'] = true;
        return $this;
    }

    /**
     * AJAX URL
     * @param string|array $url
     * @return $this
     */
    public function url($url)
    {
        $this->options['url'] = Url::to($url, '');
        return $this;
    }

    /**
     * AJAX METHOD
     * @param string $method
     * @return $this
     */
    public function httpMethod($method)
    {
        $this->options['method'] = strtolower($method);
        return $this;
    }
}